package cn.sc.summer.system.runner;

import cn.sc.summer.system.service.RefreshSystemInfoService;
import lombok.extern.slf4j.Slf4j;
import org.jetbrains.annotations.NotNull;
import org.springframework.boot.CommandLineRunner;
import org.springframework.context.ApplicationListener;
import org.springframework.context.event.ContextClosedEvent;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * 类名：服务启动与关闭时对服务器资源进行操作
 *
 * @author a-xin
 * @date 2024/9/20 11:19
 */
@Slf4j
@Component
public class CalculateRunner implements CommandLineRunner, ApplicationListener<ContextClosedEvent> {

    @Resource
    protected RefreshSystemInfoService refreshSystemInfoService;

    /**
     * Callback used to run the bean.
     *
     * @param args incoming main method arguments
     */
    @Override
    public void run(String... args) {

    }

    /**
     * Handle an application event.
     *
     * @param event the event to respond to
     */
    @Override
    public void onApplicationEvent(@NotNull ContextClosedEvent event) {
        refreshSystemInfoService.deleteSystemInfo();
    }

}
